/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { Module } from '@ohos/hvigor';

import { BuildHotReloadResource } from '../tasks/debugger/build-hot-reload-resource.js';
import { HotReloadBuild } from '../tasks/debugger/hot-reload-build.js';
import { AssembleHap } from '../tasks/hook/assemble/assemble-hap.js';
import { BuildPreviewerRes } from '../tasks/hook/previewer/build-previewer-res.js';
import { PreviewBuild } from '../tasks/hook/previewer/preview-build.js';
import { UnitTestBuild } from '../tasks/unitTest/unit-test-build.js';

import { AbstractHapModulePlugin } from './common/abstract-hap-module-plugin.js';

/**
 * 对外暴露hap级别的接口和任务的plugin
 *
 * @since 2021/12/16
 */
export class HapPlugin extends AbstractHapModulePlugin {
  private buildHotReloadRes: BuildHotReloadResource | undefined;
  private hotReloadBuild: HotReloadBuild | undefined;

  constructor(module: Module) {
    super(module);
  }

  initHapTasks(): void {
    this.assembleHap = new AssembleHap(this._moduleService!, false);
    this.buildPreviewerRes = new BuildPreviewerRes(this._moduleService!, false);
    this.previewBuild = new PreviewBuild(this._moduleService!, false);
    this._module.registry(this.assembleHap);
    this._module.registry(this.buildPreviewerRes);
    this._module.registry(this.previewBuild);
    this.buildHotReloadRes = new BuildHotReloadResource(this._moduleService!);
    this._module.registry(this.buildHotReloadRes);
    this.hotReloadBuild = new HotReloadBuild(this._moduleService!);
    this._module.registry(this.hotReloadBuild);
    this.unitTestBuild = new UnitTestBuild(this._moduleService!, false);
    this._module.registry(this.unitTestBuild);
  }
}
